<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=no,minimum-scale=1,initial-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="applicable-device" content="mobile">
    <title>{$title}</title>
    <script type="text/javascript" src="__PUBLIC__/js/do.js" charset="utf-8"></script>
    <script type="text/javascript" src="__PUBLIC__/js/moble.js" charset="utf-8"></script>
    <link rel="stylesheet" href="__STATIC__/allwin/style.css" />
</head>
<body ontouchstart>
<style>
    .demos-title {
        text-align: center;
        font-size: 34px;
        color: #333;
        font-weight: 400;
        margin: 0 15%;
    }
    .bill_bd{
        display: none;
        height: 100%;
        overflow: auto;
    }
    .bill_bd_active{
        display: block;
    }
    .bill{
        position: relative;
        display: block;
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        flex: 1;
        padding: 13px 0;
        text-align: center;
        font-size: 15px;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    .bill_on{
        color: #666;
        background-color: #f1f1f1;
    }
    .weui-tabbar__icon{
        line-height: 27px;
    }
    .demos-header{
        background-color: #fafafa;
        padding: 20px 0px;
    }
    .index-png div:first-child{
        width: 35px;
        height: 40px;
        background-size: 35px 35px;
        float: left;
        background-repeat: no-repeat;
        margin: 10px 5px;
    }
    .index-png{
        width: 45%;
        float: left;
        margin-left: 15px;
        height: 85px;
    }
    .category-title{
        font-size: 16px;
    }
    .category-content{
        font-size: 12px;
        color: rgb(193,193,193);
    }
    .index-title{
        color: #bbd000;
        font-size: 22px;
        text-align: center;
        font-weight: bold;
        margin-top: 30px;
        line-height: 40px;
    }
    .index-title-content{
        color: #bbd000;
        text-align: center;
        font-size: 15px;
        margin-bottom: 25px;
    }
    .index-title-png{
        background-image: url(/static/allwin/agent/9.png);
        width: 90%;
        height: 100%;
        margin-left: 5%;
        background-size: 100% 55%;
        background-repeat: no-repeat;
        border-radius: 5px;
    }
    .index-second-title-png{
        background-image: url(/static/allwin/agent/10.png);
        width: 100%;
        height: 110%;
        background-repeat: no-repeat;
        margin-top: -178px;
        background-size: 100% 61%;
    }
    .index-second-title-png-item{
        height: 70%;
        margin-top: -80px;
        background-size: 100% 100%;
    }
    .index-title-font{
        color: #fff;
        font-size: 20px;
    }
    .join-worker{
        color: #bbd000;
        background-color: #3e3e3e;
        height: 50px;
        line-height: 50px;
        text-align: center;
        margin: -270px 15% 0px 15%;
        border-radius: 25px;
        font-weight: bold;
        font-size: 20px;
        box-shadow: 0px 3px 1px -2px rgba(0,0,0,0.2), 0px 2px 2px 0 rgba(0,0,0,0.14), 0px 1px 5px 0 rgba(0,0,0,0.12);
    }
    .city-png{
        background-image: url(/static/allwin/agent/11.png);
        width: 101%;
        height: 100%;
        background-size: 100% 35%;
        background-repeat: no-repeat;
        margin-top: 17px;
    }
    .worker-name{
        padding: 5% 0px 0px 9%;
        font-size: 20px;
        font-weight: bold;
    }
    .worker-introduce{
        font-size: 12px;
        padding-left: 9%;
        color: #a0a0a0;
    }
    .worth-title{
        margin-left: 62%;
        margin-top: -55px;
        font-size: 14px;
    }
    .index-top-png{
        background-image: url(/static/allwin/agent/12.png);
        height: 140px;
        background-size: 100% 100%;
    }
    .weui-popup .content_page label.weui-label{
        font-size: 17px;
    }
    .item3-head{
        width: 50px;
        height: 50px;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        border-radius: 50px;
        position: relative;
        top: 15px;
        left: 15px;
    }
    .item3-name{
        position: relative;
        top: -40px;
        left: 100px;
        font-weight: bold;
        font-size: 16px;
        color: #fff;
    }
    .item3-city{
        /*background-image: url(/static/allwin/agent/13.png);*/
        position: relative;
        top: -30px;
        left: 75px;
        background-size: 6% 100%;
        background-repeat: no-repeat;
        text-indent: 25px;
    }
    .item3-money{
        /*background-image: url(/static/allwin/agent/14.png);*/
        position: relative;
        right: -60%;
        top: -52px;
        background-size: 6% 100%;
        background-repeat: no-repeat;
        text-indent: 25px;
    }
    .item3-store-num{
        /*background-image: url(/static/allwin/agent/15.png);*/
        position: relative;
        top: -5px;
        background-size: 6% 100%;
        background-repeat: no-repeat;
        text-indent: 25px;
    }
    .item3-vip-count{
        /*background-image: url(/static/allwin/agent/16.png);*/
        position: relative;
        right: -30%;
        top: -27px;
        background-size: 7% 100%;
        background-repeat: no-repeat;
        text-indent: 25px;
    }
    .item3-store-sum{
        /*background-image: url(/static/allwin/agent/14.png);*/
        position: relative;
        right: -60%;
        top: -50px;
        background-size: 6% 100%;
        background-repeat: no-repeat;
        text-indent: 25px;
    }
    .box-shadow{
        margin: 5px;
        box-shadow: 0px 3px 1px -2px rgba(0, 0, 0, 0.1), 0px 2px 2px 0 rgba(0, 0, 0, 0.14), 0px 1px 5px 0 rgba(0, 0, 0, 0.12);
        border-radius: 15px;
    }
    .demos-second-title{
        text-align: center;
        font-size: 24px;
        color: #3cc51f;
        font-weight: 400;
        margin: 0 15%;
    }
</style>
<div class="wrapper">
    <!--消息体-->
    {if empty($worker)}
    <div style="background-color: #fff;height: 100%;">
        <div style="background-color:#bbd900;height: 283px;padding-top: 1rem">
            <div class="index-title-png">
                <div class="index-title-font worker-name">合伙人</div>
                <div class="index-title-font worker-introduce">每天现金领不停</div>
                <div class="index-title-font worth-title">￥<span style="font-size: 30px;">{$setting.workers_on_amount}</span></div>
            </div>
            <div class="index-second-title-png"></div>
            <div class="join-worker" onclick="javascript:router.setRoute('workerSla')">我要加入合伙人</div>
            <div class="city-png"></div>
        </div>
        <div style="padding: 0px 5px;background-color: #fff;">
            <div class="index-title">合伙人专属权益</div>
            <div class="index-title-content">享千店加盟费和服务费</div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/7.png)"></div>
                <div class="category-title">消费省钱</div>
                <div class="category-content">消费减免，还能领取优惠券优惠</div>
            </div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/2.png)"></div>
                <div class="category-title">分享赚钱</div>
                <div class="category-content">分享朋友使用，买一送二，还能赚佣金</div>
            </div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/5.png)"></div>
                <div class="category-title">服务费收益</div>
                <div class="category-content">享所属好店服务费收益</div>
            </div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/1.png)"></div>
                <div class="category-title">代言+收益</div>
                <div class="category-content">平台店员会员20元/人</div>
            </div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/3.png)"></div>
                <div class="category-title">加盟费收益</div>
                <div class="category-content">享所属联盟商的加盟费收入</div>
            </div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/6.png)"></div>
                <div class="category-title">消费返佣收益</div>
                <div class="category-content">所属好店每笔交易服务费的10%返佣</div>
            </div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/4.png)"></div>
                <div class="category-title">店铺代言</div>
                <div class="category-content">店铺代言，最高享40%返佣</div>
            </div>
            <div class="index-png">
                <div style="background-image: url(__STATIC__/allwin/agent/8.png)"></div>
                <div class="category-title">轻松创业</div>
                <div class="category-content">自由创业，月入过万不是梦</div>
            </div>
            <div style="clear: both"></div>
        </div>
        <div class="weui-cells" style="display: none">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" id='picker' placeholder="请选择您的城市" style="text-align: center"/>
                </div>
            </div>
        </div>
    </div>
    {elseif $worker.pay_state == 0 || $worker.is_pass == 0 || $worker.is_lock == 1 /}
    <div class="weui-msg">
        <div class="index-top-png" style=" margin-bottom: 36px;margin-top: -36px;"></div>
        <div class="weui-msg__icon-area"><i class="weui-icon-warn weui-icon_msg" style="color: #bbd000"></i></div>
        <div class="weui-msg__text-area">
            {if $worker.pay_state == 0 /}  <h2 class="weui-msg__title">您还未缴纳合伙人费用</h2> <p class="weui-msg__desc">现在去支付</p>
            {elseif $worker.is_pass == 0 /}<h2 class="weui-msg__title">恭喜您，加入合伙人</h2> <p class="weui-msg__desc">您的资料正在审核中，请稍后！</p>
            {elseif $worker.is_lock == 1 /}<h2 class="weui-msg__title">您的帐户存在异常</h2> <p class="weui-msg__desc">登录帐号被锁定，请联系公司进行重置</p>
            {/if}
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                {if $worker.pay_state == 0 /} <a href="javascript:;" class="weui-btn weui-btn_default" onclick="pay()" style="width: 30%;background-color: #bbd000;">确认支付</a>
                {else/}<a href="javascript:;" class="weui-btn weui-btn_default" onclick="javascript :history.back(-1);" style="width: 50%;background-color: #bbd000;">返回</a>
                {/if}
            </p>
        </div>
    </div>
    {else/}
    <!--    主体-->
    <div class="weui-tab">
        <div class="weui-tabbar">
            <a href="#tab1" class="weui-tabbar__item">
                <div class="weui-tabbar__icon">
                    <i class="iconfont icon-store_icon weui-bar__item--on" style="color: orange"></i>
                </div>
                <p class="weui-tabbar__label">好店</p>
            </a>
            <a href="#tab2" class="weui-tabbar__item">
                <div class="weui-tabbar__icon">
                    <i class="iconfont icon-add_icon" style="color:rgb(26, 173, 25)"></i>
                </div>
                <p class="weui-tabbar__label">增加好店</p>
            </a>
            <a href="#tab3" class="weui-tabbar__item">
                <div class="weui-tabbar__icon">
                    <i class="iconfont icon-server_icon" style="color: violet"></i>
                </div>
                <p class="weui-tabbar__label">统计</p>
            </a>
        </div>
        <div class="weui-tab__bd" style="background-color: #fff;">
            <div class="weui-tab__bd">
                <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active" style="background-color: white"></div>
                <div id="tab2" class="weui-tab__bd-item"></div>
                <div id="tab3" class="weui-tab__bd-item"></div>
            </div>
        </div>
    </div>
    {/if}
</div>
<div id="store_bill" class="weui-popup weui-popup__container fn-hide order" style="z-index: 600;">
    <div class="weui-popup__modal">
        <div class="content_page" style="background-color: #fff"><div class="popup" id="store_bill-view" style="margin-top: 0px"><!--店铺详情--></div></div>
    </div>
</div>
<!--    新增好店-->
<script id="add_tpl" type="text/html">
    <div class="index-top-png" style="background-image: url(__STATIC__/allwin/agent/17.png)"></div>
    <form id="form" style="margin-top: -20px;">
        <input type="hidden" name="manage_uid" id="manage_uid">
        <input type="hidden" name="id" id="id">
        <input type="hidden" name="img" id="img">
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">好店店长：</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="绑定手机号或昵称" value="" name="user_name">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">服务费:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" placeholder="‰" pattern="[0-9]*" name="charges" value="">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">营业时间:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="例8:00-12:00"  name="work_time" value="">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">好店名称:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="" name="name" value="">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">地址:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="省/市/县/区/街道门牌号" name="address" value="">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">电话:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" placeholder="门店电话" name="telphone" value="">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">关键词:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="如：满30元送60元" name="tags" value="">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <div class="weui-uploader">
                        <div class="weui-uploader__hd">
                            <p class="weui-uploader__title">商家图片</p>
                        </div>
                        <div class="weui-uploader__bd">
                            <ul class="weui-uploader__files" id="uploaderFiles"></ul>
                            <div class="weui-uploader__input-box">
                                <input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple="" name="imgs">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <label for="weuiAgree" class="weui-agree" onclick="javascript:if($('#weuiAgree').is(':checked')){router.setRoute('storeSla')}">
                <input id="weuiAgree" type="checkbox" class="weui-agree__checkbox" placeholder="请先同意协议">
                <span class="weui-agree__text">
                    阅读并同意<a href="javascript:;">《服务协议》</a>
                </span>
            </label>
        </div>
    </form>
    <a href="javascript:;" class="weui-btn weui-btn_default submit" style="margin: 20px 20px 100px 20px;">确定</a>
</script>
<!--    修改好店-->
<script id="edit_tpl" type="text/html">
    {literal}
    <form id="form">
        <input type="hidden" name="manage_uid" id="manage_uid" value="{{item.store.manage_uid}}">
        <input type="hidden" name="id" id="id" value="{{item.store.id}}">
        <input type="hidden" name="img" id="img" value="{{item.store.img}}">
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">好店店长:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="绑定手机号或昵称" value="{{item.user.nickname}}" name="user_name">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">服务费:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" placeholder="‰" pattern="[0-9]*" name="charges" value="{{item.store.charges}}">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">营业时间:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="例8:00-12:00"  name="work_time" value="{{item.store.work_time}}">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">好店名称:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="" name="name" value="{{item.store.name}}">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">地址:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="省/市/县/区/街道门牌号" name="address" value="{{item.store.address}}">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">电话:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="number" placeholder="门店电话" name="telphone" value="{{item.store.telphone}}">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">关键词:</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" placeholder="如：满30元送60元" name="tags" value="{{item.store.tags}}">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <div class="weui-uploader">
                        <div class="weui-uploader__hd">
                            <p class="weui-uploader__title">商家图片</p>
                        </div>
                        <div class="weui-uploader__bd">
                            <ul class="weui-uploader__files" id="uploaderFiles">
                                <li class="weui-uploader__file" style="background-image:url({{item.store.img}})">
                            </ul>
                            <div class="weui-uploader__input-box" style="opacity: 0;margin-left: -86px;">
                                <input id="uploaderInput" class="weui-uploader__input" type="file" accept="image/*" multiple="" name="imgs" >
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <p class="weui-media-box__desc" style="padding: 10px;color: red;">提示：重新提交资料后，店铺会被锁定，需要管理员审核通过后才会显示，请慎重修改。</p>
        </div>
    </form>
    <a href="javascript:;" class="weui-btn weui-btn_default submit" style="margin: 20px 20px">确定</a>
    {/literal}
</script>
<script id="store_tpl" type="text/html">
    <div class="index-top-png"></div>
    {literal}
    {{each item value}}
    <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg" attr="{{value.id}}" is_lock="{{value.is_lock}}">
        <div class="weui-media-box__hd">
            <img class="weui-media-box__thumb" src="{{value.img}}">
        </div>
        <div class="weui-media-box__bd">
            <h4 class="weui-media-box__title">{{value.name}}</h4>
            <p class="weui-media-box__desc">{{value.address}}</p>
            <ul class="weui-media-box__info">
                <li class="weui-media-box__info__meta">{{value.cate_name}}</li>
                <li class="weui-media-box__info__meta">{{value.telphone}}</li>
                {{if value.is_lock}}<li class="weui-media-box__info__meta" style="color: red">待审核</li>{{/if}}
            </ul>
        </div>
    </a>
    {{/each}}
    {/literal}
</script>
<script id="store_bill_tpl" type="text/html">
    <header class="demos-header">
        <h1 class="demos-title">{{item.payment}}</h1>
    </header>
    <div class="weui-tab">
        <div class="weui-navbar">
            <a class="weui-navbar__item store weui-bar__item--on" href="#store1">今天</a>
            <a class="weui-navbar__item store " href="#store2">昨天</a>
            <a class="weui-navbar__item store" href="#store3">前天</a>
        </div>
        <div class="weui-tab__bd">
            <div id="store1" class="weui-tab__bd-item weui-tab__bd-item--active"></div>
            <div id="store2" class="weui-tab__bd-item"></div>
            <div id="store3" class="weui-tab__bd-item"></div>
        </div>
    </div>
</script>
<script id="store_day_tpl" type="text/html">
    {{each item value}}
    <div class="box-shadow">
        <div class="weui-form-preview__hd">
            <label class="weui-form-preview__label">{{value.message}}</label>
            <em class="weui-form-preview__value">¥{{value.money}}</em>
            <div class="weui-form-preview__bd" style="padding: 0px;font-size: 0.5em;">
                <div class="weui-form-preview__item">
                    <span class="weui-form-preview__value">{{value.update_time | dateFormat 'yyyy-MM-dd hh:mm:ss'}}</span>
                </div>
            </div>
        </div>
    </div>
    {{/each}}
</script>
<script id="all_bill_head_tpl" type="text/html">
    {literal}
    <div style="height: 200px;padding-top: 0.6rem;padding-bottom: 0.6rem;background-color: rgb(250, 250, 250);">
        <div class="index-title-png" style="background-size: 100% 100%;color: #a0a0a0;font-size: 14px;width: 94%;margin-left: 3%;overflow: hidden;">
            <div style="background-image: url({{item.user.face}});" class="item3-head"></div>
            <div class="item3-name">{{item.user.nickname}}</div>
            <div class="item3-city">合伙人</div>
            <div class="item3-money">余&nbsp;&nbsp;额&nbsp;<span  style="font-weight: normal;margin-left: 10px;"><span style="font-size: 10px;">￥</span>{{if item.bank}}{{item.bank.due_money/100}}{{else}}0{{/if}}</span></div>
            <div class="item3-store-num">好店数量<span style="font-weight: normal;margin-left: 10px;">{{item.storeNum}}</span></div>
            <div class="item3-vip-count">会员数量<span style="font-weight: normal;margin-left: 10px;">{{item.vipNum}}</span></div>
            <div class="item3-store-sum">交易额<span style="font-weight: normal;margin-left: 8px;"><span style="font-size: 10px;">￥</span>{{item.sum}}</span></div>
        </div>
    </div>
    {/literal}
    <div class="weui-tab">
        <div class="weui-navbar">
            <a class="bill bill_on" href="javascript:;" onclick="clickBill(this,1)">今天</a>
            <a class="bill" href="javascript:;" onclick="clickBill(this,2)">昨天</a>
            <a class="bill" href="javascript:;" onclick="clickBill(this,3)">前天</a>
        </div>
        <div class="weui-tab__bd">
            <div id="bill1" class="bill_bd bill_bd_active"></div>
            <div id="bill2" class="bill_bd"></div>
            <div id="bill3" class="bill_bd"></div>
        </div>
    </div>
</script>
<script id="all_bill_tpl" type="text/html">
    {{each item value}}
    <div class="box-shadow">
        <div class="weui-form-preview__hd">
            <label class="weui-form-preview__label">{{value.message}}</label>
            <em class="weui-form-preview__value">¥{{value.money}}</em>
            <div class="weui-form-preview__bd" style="padding: 0px;font-size: 0.5em;">
                <div class="weui-form-preview__item">
                    <span class="weui-form-preview__value">{{value.update_time | dateFormat 'yyyy-MM-dd hh:mm:ss'}}</span>
                </div>
            </div>
        </div>

    </div>
    {{/each}}
</script>
<script id="clickLoading" type="text/html">
    <div class="weui-footer" style="padding-top: 20px">
        <p class="weui-footer__links">
            <a href="javascript:void(0);" class="weui-footer__link" onclick="infinite_view_2('{{type}}','{{dom}}','{{page}}','{{id}}')">加载更多</a>
        </p>
    </div>
</script>
<script id="worker_sla_tpl" type="text/html">
    <header class="demos-header" style="background-color: transparent;">
        <h2 class="demos-second-title">服务协议</h2>
    </header>
    <article class="weui-article">
        {$sla|dehtml|raw}
    </article>
    <a href="javascript:;" class="weui-btn weui-btn_default" style="margin: 20px 20px"onclick="javascript :history.back(-1);pay()">同意协议</a>
</script>
<script id="store_sla_tpl" type="text/html">
    <header class="demos-header" style="background-color: transparent;">
        <h2 class="demos-second-title">服务协议</h2>
    </header>
    <article class="weui-article">
        {$sla|dehtml|raw}
    </article>
    <a href="javascript:;" class="weui-btn weui-btn_default" style="margin: 20px 20px"onclick="javascript :history.back(-1)">同意协议</a>
</script>
<script id="tips" type="text/html">
    <div class="weui-msg">
        <div class="index-top-png" style="margin-top: -36px;margin-bottom: 36px;"></div>
        <div class="weui-msg__icon-area"><i class="weui-icon-warn weui-icon_msg" style="color: #bbd000"></i></div>
        <div class="weui-msg__text-area">
            <h2 class="weui-msg__title">未找到店铺</h2> <p class="weui-msg__desc">请先添加好店</p>
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" class="weui-btn weui-btn_default" onclick="onAddStore()" style="width: 50%;background-color: #bbd000;color: #fff;">现在去添加好店</a>
            </p>
        </div>
    </div>
</script>
<script id="empty" type="text/html"><div class="weui-loadmore weui-loadmore_line fn-clear" id="buttom"><span class="weui-loadmore__tips" style="background-color:#fff">已到底部</span></div></script>
<script id="loading" type="text/html"><div class="weui-loadmore"><i class="weui-loading"></i><span class="weui-loadmore__tips">正在加载</span></div></script>
<script type="text/javascript">
    var hash=window.location.hash;""==hash&&history.replaceState(null,null,"#/"); //修正网址
    Do('jqweui','jweixin','fastclick','routes','tpl',function(){
        $(function(){
            FastClick.attach(document.body);
        });
        wx.config({$weconfig|raw});
        $.showLoading();
        item(1,1,'#tab1');
        infinite(1,'#tab1');
        // 主页menu切换
        $(".weui-tabbar__item").on('click',function() {
            var index = $('.weui-bar__item--on').attr('href');
            var dom = $(this).attr("href");
            if (index == dom) return false;
            $.showLoading();
            $(dom + " > .weui-loadmore").remove();
            var type = 2;
            switch (dom) {
                case "#tab1":
                    type = 1;
            break;
                case "#tab3":
                    type = 3;
                    break;
                default:
                    type = 2
            }
            if(type == 2 && incomplete()) return false;
            // 清除页面残留信息,清除绑定事件
            $(dom).animate({scrollTop: 0,screenLeft: 0,}, 400);
            $(dom).empty();
            $(dom).unbind();
            // 获取数据 绑定滚动事件
            item(1,type,dom);
            infinite(type,dom);
        })
        // 开启路由
        var home = function(){}
        var routes = {'/':home,'/store_bill/:id':store_bill,'/store_by_id/:id':store_by_id,'/workerSla':workerSla,'/storeSla':storeSla};
        var allroutes = function(){
            var route=window.location.hash.slice(2);
            null!=route&&""!=route?($("#store_bill").popup(),$(document.body).addClass("html-body-overflow")):($.closePopup(),$(document.body).removeClass("html-body-overflow"));
        };
        router = Router(routes);
        router.config({on:allroutes});
        router.init();
        // setTimeout(function(){
        //     incomplete();
        //     $.hideLoading();
        // },100);
    })
    // tabar1滚动加载
    function infinite(type,dom){
        if(type == 3 || type == 2){
            return;
        }
        var loading = false;
        var pages   = 1;
        $(dom).infinite(50).on("infinite",function(){
            if(loading){
                return;
            }
            pages++;
            loading = true;
            $(dom).append(template("loading"));
            setTimeout(function(){
                    loading = item(pages,type,dom)
            },600);
        });
    }
    // tabar1弹出页面点击加载
    function infinite_view_2(type,dom,pages,id){
        $('#store'+type + ".weui-tab__bd-item > .weui-footer").remove();
        var loading =true;
        pages++;
        $(dom).append(template("loading"));
        setTimeout(function(){
            loading = item_view_1(pages,type,dom,id)
        },600);
    }
    // tabar3滚动加载
    function infinite_view_3(type,dom){
        var loading = false;
        var pages   = 1;
        $(dom).infinite(50).on("infinite",function(){
            if(loading){
                return;
            }
            pages++;
            loading = true;
            $(dom).append(template("loading"));
            setTimeout(function(){
                    loading = item_view_3(pages,type,dom)
            },600);
        });
    }
    // tabar1弹出页面帐单列表获取数据
    function item_view_1(page,type,dom,id){
        $(dom + ".weui-tab__bd-item > .weui-loadmore").remove();
        var loading = false;
        $.ajaxSetup({async:false});
        $.getJSON("{:urls('allwin-agent-storeBillList',$member_miniapp_id)}",{id:id,page:page,type:type},function(data) {
            if(200==data.code){
                var html = template("store_day_tpl",{item:data.data.data,page:page});
            }else{
                var html = template("empty");
                loading=true
            }
            1==page?$(dom).html(html):$(dom).append(html);
            if(data.code == 200 && page != data.data.last_page){
                $(dom).append(template("clickLoading",{type:type,dom:dom,page:page,id:id}));
            }else if(data.code == 200 && page == data.data.last_page){
                $(dom).append(template("empty"));
            }
            $.hideLoading();
        });
        return loading;
    }
    // tabar3列表获取数据
    function item_view_3(page,type,dom){
        $(dom + ".bill_bd > .weui-loadmore").remove();
        var loading = false;
        $.ajaxSetup({async:false});
        $.getJSON("{:urls('allwin/agent/allBill',$member_miniapp_id)}",{type:type,page:page},function(data) {
            if(200==data.code){
                var html = template("all_bill_tpl",{item:data.data.data,page:page});
            }else{
                var html = template("empty");
                loading=true
            }
            $(dom).append(html);
            $.hideLoading();
        });
        return loading;
    }
    // 首页三个Menu切换获取数据
    function item(page,type,dom){
        $(dom + ".weui-tab__bd-item > .weui-loadmore").remove();
        var loading = false;
        if(type == 1){
            $.ajaxSetup({async:false});
            $.getJSON("{:urls('allwin/agent/myStore',$member_miniapp_id)}",{page:page},function(data) {
                if(200==data.code){
                    var html = template("store_tpl",{item:data.data.data,page:page});
                }else if(1 == page && data.code != 200){
                    var html = template("tips");
                    loading=true
                }
                1==page?$(dom).html(html):$(dom).append(html);
                // 为列表里的每项绑定点击事件
                $('.weui-media-box_appmsg').unbind();
                $('.weui-media-box_appmsg').click(function () {
                    var id = $(this).attr('attr');
                    var is_lock = $(this).attr('is_lock');
                    $.actions({
                        actions: [{
                            text: "编辑",
                            onClick: function() {
                               if(is_lock == "1") {$.alert('该好店还在审核中'); return};
                                $.showLoading();
                                $('#tab2').empty();
                                router.setRoute('store_by_id/'+id);
                            }
                        },{
                            text: "查看数据",
                            onClick: function() {
                                if(is_lock == "1") {$.alert('该好店还在审核中'); return};
                                $.showLoading();
                                $.getJSON("{:urls('allwin/agent/getStoreBill',$member_miniapp_id)}?id="+id,function(data) {
                                    if(200==data.code && data.data != null){
                                        router.setRoute('store_bill/'+id);
                                    }else{
                                        $.alert("没有内容");
                                        $.hideLoading();
                                    }
                                });
                            }
                        }]
                    });
                })
                $.hideLoading();
            });
        }else if(type == 2){
            $("#store_bill-view > *").remove();
            var res = template("add_tpl");
            $(dom).html(res);
            submitStore();
            $.hideLoading();
        }else if(type == 3){
            $.getJSON("{:urls('allwin/agent/allBillSum',$member_miniapp_id)}",function(data) {
               if( 200==data.code && data.data != 0){
                   var  html = template("all_bill_head_tpl",{item:data.data});
                   $(dom).html(html);
                   item_view_3(1,1,'#bill1');
                   infinite_view_3(1,'#bill1');
               }else{
                   var html = template("tips");
                   $(dom).html(html);
                   $.hideLoading();
               }
            });
        }
        return loading;

    }
    // 格式化时间
    function dateFormat(date, format) {
        date = new Date(date * 1000);
        var map = {
            "M": date.getMonth() + 1, //月份
            "d": date.getDate(), //日
            "h": date.getHours(), //小时
            "m": date.getMinutes(), //分
            "s": date.getSeconds(), //秒
            "q": Math.floor((date.getMonth() + 3) / 3), //季度
            "S": date.getMilliseconds() //毫秒
        };
        format = format.replace(/([yMdhmsqS])+/g, function(all, t){
            var v = map[t];
            if(v !== undefined){
                if(all.length > 1){
                    v = '0' + v;
                    v = v.substr(v.length-2);
                }
                return v;
            }
            else if(t === 'y'){
                return (date.getFullYear() + '').substr(4 - all.length);
            }
            return all;
        });
        return format;
    };
    function fileSize(file, limitSize) {
        var arr = ["KB", "MB", "GB"]
        var limit = limitSize.toUpperCase();
        var limitNum = 0;
        for (var i = 0; i < arr.length; i++) {
            var leval = limit.indexOf(arr[i]);
            if (leval > -1) {
                limitNum = parseInt(limit.substr(0, leval)) * Math.pow(1024, (i + 1))
                break
            }
        }
        if (file.size > limitNum) {
            return false
        }
        return true
    }

    // tabar1 弹出单个店铺帐单
    var store_bill = function(id){
        $("#store_bill-view > *").remove();
        $('#store1' + ".weui-tab__bd-item > .weui-loadmore").remove();
        $.getJSON("{:urls('allwin/agent/getStoreBill',$member_miniapp_id)}?id="+id,function(data) {
            if(200==data.code && data.data != null){
                $("#store_bill-view").html(template("store_bill_tpl",{item:data.data}))
                item_view_1(1,1,'#store1',id);
                $(".weui-navbar__item").on('click',function() {
                    var dom = $(this).attr("href");
                    var index = $('.weui-bar__item--on:eq(1)').attr('href');
                    if (index == dom) return false;
                    $.showLoading();
                    $(dom + " > .weui-loadmore").remove();
                    var type = 1;
                    switch (dom) {
                        case "#store2":
                            type = 2;
                            break;
                        case "#store3":
                            type = 3;
                            break;
                        default:
                            type = 1
                    }
                    item_view_1(1,type,dom,id);
                })
            }
            $.hideLoading();
        });

    }
    // tabar1 弹出单个店铺详情修改
    var store_by_id = function(id){
        $("#store_bill-view > *").remove();
        $.getJSON("{:urls('allwin/agent/getDataById',$member_miniapp_id)}?id="+id,function(data) {
            200==data.code&&$("#store_bill-view").html(template("edit_tpl",{item:data.data}))
            submitStore();
            $.hideLoading();
        });

    }
    // 为添加修改好店绑定提交事件
    function submitStore(){
        $(".submit").unbind();
        $(".uploaderInput").unbind();
        $("input[name=user_name]").unbind();
        $(".submit").click(function(){
            var id = $('#id').val();
            if(!id){
                if(!$('#weuiAgree').is(':checked')){
                    $.alert('请先同意服务协议');
                    return false;
                }
            }
            $(".submit").unbind();
            $.ajax({
                type: "POST",
                url:"{:urls('allwin/agent/edit',$member_miniapp_id)}",
                data:$("#form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.code == 200 && data.data != 0) {
                        $.alert(data.msg, function () {
                            if(id){ history.back(-1)};
                            setTimeout(function(){
                                window.location.reload();
                            },1000);
                        });
                    } else if (data.code == 206) {
                        wx.chooseWXPay({
                            "timestamp": data.data.timestamp,
                            "nonceStr": data.data.nonceStr,
                            "package": data.data.package,
                            "signType": data.data.signType,
                            "paySign": data.data.paySign,
                            success: function (res) {
                                if(id){ history.back(-1)};
                                setTimeout(function(){
                                    window.location.reload();
                                },1000);
                            },
                            fail:function(res){
                                window.location.reload();
                            },
                            cancel:function(res){
                                window.location.reload();
                            }
                        })
                    } else {
                        $.alert(data.msg);
                        submitStore();
                    }
                }
            })
        });
        // tabar2失去焦点时获取用户信息
        $("input[name=user_name]").blur(function(){
            var value = $("input[name=user_name]").val().trim();
            if(!value){
                $("input[name=user_name]").parent().prev().has('img').remove();
                $("input[name=user_name]").val('');
                $('#manage_uid').val(null);
                return;
            }
            $.getJSON("{:urls('allwin/agent/getUser',$member_miniapp_id)}?key="+value,function(data) {
                if(data.code == 200 && data.data != '' && data.data != null){
                    $("input[name=user_name]").parent().prev().has('img').remove();
                    $("input[name=user_name]").val(data.data.nickname);
                    $("input[name=user_name]").parent().before(' <div class="weui-cell__hd" ><img style="max-width: 25px;" src="'+data.data.face+'"></div>');
                    $('#manage_uid').val(data.data.id);
                }else{
                    $("input[name=user_name]").parent().prev().has('img').remove();
                    $("input[name=user_name]").val('');
                    $('#manage_uid').val(null);
                    $.alert(data.msg);
                }
            });
        });
        // 图片上传
        $("#uploaderInput").change(function(){
            var img = document.forms[0].imgs.files[0];
            if(!fileSize(img,"10MB")){
                $.alert('上传图片最大限制10MB');
                return;
            }
            var fm = new FormData();
            fm.append('img', img);
            $.ajax({
                url: "{:urls('allwin/agent/upImg',$member_miniapp_id)}", type: 'POST', data: fm, contentType: false, //禁止设置请求类型
                processData: false,
                success: function (result) {
                    if(result.code == 200){
                        $('#uploaderFiles').empty();
                        $('#uploaderFiles').append('<li class="weui-uploader__file" style="background-image:url('+result.data+')"></li>');
                        $('#img').val(result.data);
                        $('.weui-uploader__input-box').css({"opacity": 0,"margin-left": "-86px"});
                    }
                }
            });
        });
    }
    // tabar3点击切换
    function clickBill(div,type){
        $.showLoading();
        var dom = '#bill'+type;
        $(dom).empty();
        $(dom).unbind();
        item_view_3(1,type,dom),infinite_view_3(type,dom);
        $(div).siblings('.bill').each(function(){
            if($(this).hasClass('bill_on')){
                $(this).removeClass("bill_on");
            }
        })
        $(dom).siblings('.bill_bd').each(function(){
            if($(this).hasClass('bill_bd_active')){
                $(this).removeClass("bill_bd_active");
            }
        })
        $(div).addClass('bill_on');
        $(dom).addClass('bill_bd_active');
    }
    //支付
    function pay(){
        $.post("{:urls('allwin/agent/pay',$member_miniapp_id)}?id={$worker.id}",function(rel) {
            if(rel.code == 200){
                wx.chooseWXPay({
                    "timestamp":rel.data.timestamp,
                    "nonceStr":rel.data.nonceStr,
                    "package":rel.data.package,
                    "signType":rel.data.signType,
                    "paySign":rel.data.paySign,
                    success:function (res){
                        setTimeout(function(){
                            window.location.reload();
                        },2000);
                    },
                    fail:function(res){
                        window.location.reload();
                    },
                    cancel:function(res){
                        window.location.reload();
                    }
                })
            }else{
                $.alert(rel.msg);
            }
        });
        return;
    }
    var workerSla = function(){
        $("#store_bill-view > *").remove();
        $("#store_bill-view").html(template("worker_sla_tpl"))
    }
    var storeSla = function(){
        $("#store_bill-view > *").remove();
        $("#store_bill-view").html(template("store_sla_tpl"))
    }
    function onAddStore(){
        $('.weui-tabbar__item:eq(1)').click();
        incomplete();
    }
    function incomplete(){
        {if $worker && $workerOnStore}
        $('.weui-tabbar__item:eq(0)').click();
        $('#tab2').empty();
        router.setRoute('store_by_id/'+{$workerOnStore.store_id});
        return true;
        {/if}
        return false;
    }
</script>
</body>
</html>